﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;

/// <summary>
///Tools 的摘要说明
/// </summary>
public class Tools
{
	public Tools()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public static void WriteTxt(string txt,string path)
    {
        using (StreamWriter sw = File.CreateText(path)){
            sw.WriteLine(txt);
        }
    }
    public static string ReadText(string filepath)
    {
        string txt = string.Empty;
        if (File.Exists(filepath))
        {
            using (StreamReader sr = File.OpenText(filepath))
            {
                txt = sr.ReadToEnd();
                //sr.Close();
            }
        }
        return txt;
    }

    public static List<T> GetRandomList<T>(List<T> inputList) {
        //Copy to a array  
        T[] copyArray = new T[inputList.Count];
        inputList.CopyTo(copyArray);

        //Add range  
        List<T> copyList = new List<T>();
        copyList.AddRange(copyArray);

        //Set outputList and random  
        List<T> outputList = new List<T>();
        Random rd = new Random(DateTime.Now.Millisecond);

        while (copyList.Count > 0) {
            //Select an index and item  
            int rdIndex = rd.Next(0, copyList.Count - 1);
            T remove = copyList[rdIndex];

            //remove it from copyList and add it to output  
            copyList.Remove(remove);
            outputList.Add(remove);
        }
        return outputList;
    }  


}